<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            阳光成单系统
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="../../../static/back/css/x-admin.css" media="all">
    </head>
    <body>
        <div class="x-body">
            <form class="layui-form" id="myform">
                {% csrf_token %}
                <div class="layui-form-item">
                    <label for="L_username" class="layui-form-label">
                        用户名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_username" name="username" disabled="" value="{{ name }}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red">*</span>旧密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_repass" name="oldpass" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_pass" class="layui-form-label">
                        <span class="x-red">*</span>新密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_pass" name="newpass" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        6到16个字符
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red">*</span>确认密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_repass" name="repass" required="" lay-verify="required"
                        autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="save" lay-submit="">
                        修改
                    </button>
                </div>
            </form>
        </div>
        <script src="../../../static/back/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="../../../static/back/js/x-layui.js" charset="utf-8">
        </script>
        <script>
            layui.use(['form','layer'], function(){
              var  $ = layui.jquery;
              var  form= layui.form
                    ,layer = layui.layer;
            form.verify({
                  username: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                      return '用户名不能有特殊字符';
                    }
                    if(/(^\_)|(\__)|(\_+$)/.test(value)){
                      return '用户名首尾不能出现下划线\'_\'';
                    }
                    if(/^\d+\d+\d$/.test(value)){
                      return '用户名不能全为数字';
                    }
                  }
                  //我们既支持上述函数式的方式，也支持下述数组的形式
                  //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
                  ,pass: [
                    /^[\S]{6,12}$/
                    ,'密码必须6到12位，且不能出现空格'
                  ]
                });
              //监听提交
              form.on('submit(save)', function(data){
                //发异步，把数据提交给服务端程序
                  var url='/back/changepwd';
                  var param=$('#myform').serialize();
                  $.post(url,param,function (data) {
                        if(data.success){
                            layer.alert('修改成功',{icon:1},function (index) {
                                window.parent.location.reload();
                                parent.layer.close(index);
                            });
                        }else{
                            layer.msg(data.message,{time:2000,icon:6})
                        }
                  },'json');
                  return false
              });
            });
        </script>
        
    </body>

</html>